package com.easysoft.framework.consult.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.consult.mapper.SysConsultationReplyMapperExtd;
import com.easysoft.framework.consult.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by try on 2017/9/12.
 *
 * 咨询回复表
 */
@Service("service.SysConsultationReplyService")
public class SysConsultationReplyService {

    @Autowired
    @Qualifier("mapper.SysConsultationReplyMapperExtd")
    private SysConsultationReplyMapperExtd sysConsultationReplyMapperExtd;
    
    @DataSource(DataSource.SLAVE)
    public List<SysConsultationReplyView> selectSysConsultationReplyListByPage(SysConsultationReplyQuery query, Page page) {

        int maxRow = sysConsultationReplyMapperExtd.selectCountSysConsultationReplyQuery(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysConsultationReplyView>();
        }
        return sysConsultationReplyMapperExtd.selectSysConsultationReplyListByPage(query,page);

    }


    @DataSource(DataSource.MASTER)
    public int addSysConsultationReply(SysConsultationReply sysConsultationReply){
        sysConsultationReply.setId(UUIDUtils.getUUID());
        sysConsultationReply.setCreateTime(new Date());
        return sysConsultationReplyMapperExtd.insertSelective(sysConsultationReply);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysConsultationReply(String id){
        return sysConsultationReplyMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysConsultationReply(SysConsultationReply sysConsultationReply){
        return sysConsultationReplyMapperExtd.updateByPrimaryKeySelective(sysConsultationReply);
    }

    public SysConsultationReply selectSysConsultationById(String id){
        return sysConsultationReplyMapperExtd.selectByPrimaryKey(id);
    }


}
